package com.lagou.edu.utils;

import com.lagou.edu.annotations.CustService;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @ClassName ConnectionUtils
 * @Description TODO
 * @Author xsl
 * @Date 2020/6/15 12:16
 * @Version 1.0
 */
@CustService
public class ConnectionUtils {

  private ThreadLocal<Connection> threadLocal = new ThreadLocal<>();

  public  Connection getCurrentThreadConn() throws SQLException {
    Connection connection = threadLocal.get();
    if(connection == null){
      connection = DruidUtils.getInstance().getConnection();
      threadLocal.set(connection);
    }
    return connection;
  }

}
